﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Logistics_Service.DTO;
using System.Data;


namespace Logistics_Service.DAO
{
    public class XeDAO
    {
        public XeDTO[] DanhSachXe()
        {
            XeDTO[] arr;
            string query = string.Format("select * from Xe");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new XeDTO[n];
            for (int i = 0; i < n; i++)
            {
                object xe = GetDataFromDataRow(dt, i);
                arr[i] = (XeDTO)xe;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            XeDTO xe = new XeDTO();
            xe.Ma = dt.Rows[i]["Ma"].ToString();
            xe.BienSo = dt.Rows[i]["BienSo"].ToString();
            xe.HangSanXuat=dt.Rows[i]["HangSanXuat"].ToString();
            xe.LoaiXe=dt.Rows[i]["LoaiXe"].ToString();
            xe.NgayMua=DateTime.Parse(dt.Rows[i]["NgayMua"].ToString());
            xe.SoGioVanChuyen=float.Parse(dt.Rows[i]["SoGioVanChuyen"].ToString());
            xe.SoQuanDuongVanChuyen=float.Parse(dt.Rows[i]["SoQuanDuongVanChuyen"].ToString());
            xe.SucChua=float.Parse(dt.Rows[i]["SucChua"].ToString());
            xe.TinhTrang = TinhTrangXeDAO.Get(dt.Rows[i]["MaTinhTrang"].ToString());
            xe.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)xe;
        }       
    }
}